<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型方法</title>
    <script>
       class Animal{
            constructor(name,character){
                this.name=name
                this.character=character
            }

            sayHello(){
                console.log("hi")
            }
       }

       class Dog extends Animal{
            constructor(name,age){
                super(name)
                this.age=age
            }
       }

       const dog = new Dog()
       const animal = new Animal()

       /*
         instanceof用来检查该对象的原型链上是否有该类实例
         dog->Animal实例->Object实例->Object原型
         */
       console.log(dog instanceof Dog)   //true
       console.log(dog instanceof Animal)    //true

       /*
       实例.__proto__或对象.prototype可查找该实例原型链上一层
       */
       console.log(dog.__proto__)    //Animal
       console.log(Dog.prototype)   //Animal

       /*
       in运算符检查属性时，无论属性在实例自身还是原型对象中，都会返回true
       */
      console.log("character" in animal)    //true
      console.log("character" in dog)   //true

      /*
      Object.hasOwn(对象，属性名)：用来检查一个对象自身是否含有某个属性
      */
     console.log(Object.hasOwn(dog,"character"))    //true
    //  consloe.log(Object.hasOwn(animal,"age"))    报错
    //  consloe.log(Object.hasOwn(animal,"sayHello"))   报错

    </script>
</head>
<body>
    
</body>
</html>